package com.itheima.controller;

import com.itheima.domain.UmsResource;
import com.itheima.manager.UmsResourceCategoryManager;
import com.itheima.manager.UmsResoureManager;
import com.itheima.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author ZhuHongKai
 * @version 1.0
 * @ClassName UmsResoureController
 * @date 2022/11/13 2:06
 */
@RestController
public class UmsResoureController {

    @Autowired
    UmsResoureManager umsResoureManager;

    @Autowired
    UmsResourceCategoryManager umsResourceCategoryManager;

    /**
     * 查询所有后台资源
     * @return
     */
    @RequestMapping(value = "/resource/listAll",method = RequestMethod.GET)
    public R listAll(){
        return umsResoureManager.listAll();
    }

    /**
     * 分页模糊查询后台资源
     * @param map
     * @return
     */
    @GetMapping("/resource/list")
    public R getList(@RequestParam(required = false) Map<String,String> map){
        return umsResoureManager.getList(map);
    }

    /**
     * 添加后台资源
     * @param umsResource
     * @return
     */
    @PostMapping("/resource/create")
    public R create(@RequestBody UmsResource umsResource){
        return umsResoureManager.create(umsResource);
    }

    /**
     * 修改后台资源
     * @param id
     * @param umsResource
     * @return
     */
    @PostMapping("/resource/update/{id}")
    public R update(@PathVariable Long id,@RequestBody UmsResource umsResource){
        return umsResoureManager.update(id,umsResource);
    }

    /**
     * 根据ID删除后台资源
     * @param id
     * @return
     */
    @PostMapping("/resource/delete/{id}")
    public R delete(@PathVariable Long id){
        return umsResoureManager.delete(id);
    }
}
